import { DEFAULT_REDIS_NAMESPACE, RedisService } from '@liaoliaots/nestjs-redis';
import { HttpException, Injectable } from '@nestjs/common';
import { EventEmitter2 } from '@nestjs/event-emitter';
import { JwtService } from '@nestjs/jwt';
import Redis from 'ioredis';
import { IRequest } from 'src/interface/common';
import { randomString } from 'src/utils';

@Injectable()
export class AuthService {
	redis:Redis
	constructor(
		private readonly jwtService: JwtService,
		private readonly redisService: RedisService,
		private readonly eventEmitter: EventEmitter2
	) {
		this.redis = this.redisService.getClient("LoginUser");
	}

	async createToken(user: any,access=[]) {
		const payload = {
			date: Date.now(),
			userId: user._id,
			access: access,
		};
		return {
			token: this.jwtService.sign(payload),
		};
	}
}
